#include "mainwindow.h"
#include "ui_mainwindow.h"

MainWindow::MainWindow(QWidget *parent)
    : QMainWindow(parent)
    , ui(new Ui::MainWindow)
{
    ui->setupUi(this);
}

MainWindow::~MainWindow()
{
    delete ui;
}

void MainWindow::on_SPI_heit_textChanged()
{
    setCurProBarPlace();
}

void MainWindow::on_SPI_weit_textChanged()
{
    setCurProBarPlace();
}

void MainWindow::setCurProBarPlace()//此函数用于更新BMI值和进度条位置
{
    QPalette setLabelColor;//要设置的级别颜色
    QString setLabelString;//要设置的级别文字
    double curBmi=this->ui->SPI_weit->value()/this->ui->SPI_heit->value()/this->ui->SPI_heit->value();
    double critValue[5]={18.5,24,28,30,40};//存储临界值
    this->ui->LAB_value->setText(QString::number(curBmi,'d',2));
    this->ui->PRO_show->setValue(curBmi*100);
    if(curBmi<critValue[0])
    {
        setLabelString="体重偏轻";
        setLabelColor.setColor(QPalette::WindowText,QColor(0,230,230));
    }
    else if(curBmi<critValue[1])
    {
        setLabelString="体重正常";
        setLabelColor.setColor(QPalette::WindowText,QColor(0,230,0));
    }
    else if(curBmi<critValue[2])
    {
        setLabelString="轻微超重";
        setLabelColor.setColor(QPalette::WindowText,QColor(220,220,0));
    }
    else if(curBmi<critValue[3])
    {
        setLabelString="轻微肥胖";
        setLabelColor.setColor(QPalette::WindowText,QColor(255,150,30));
    }
    else if(curBmi<critValue[4])
    {
        setLabelString="中度肥胖";
        setLabelColor.setColor(QPalette::WindowText,QColor(255,70,0));
    }
    else
    {
        setLabelString="严重肥胖";
        setLabelColor.setColor(QPalette::WindowText,QColor(170,90,90));
    }
    this->ui->LAB_lev->setText(setLabelString);
    this->ui->LAB_lev->setPalette(setLabelColor);
}
